package com.borko.healthcare.entities.beans;

import java.util.Random;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.borko.healthcare.entities.interfaces.Medicine;
import com.borko.healthcare.entities.interfaces.MedicineOrder;
import com.borko.healthcare.entities.interfaces.Notification;
import com.borko.healthcare.entities.interfaces.Order;

@Entity(name = "medicineorder")
@Table(name = "MEDICINE_ORDERS")
public class MedicineOrderBean implements MedicineOrder {

	@Id
	@GeneratedValue
	@Column(name = "MEDICINE_ORDER_ID")
	private int id;

	private long orderNumber;

	private int qty;

	private double price;

	@OneToOne(targetEntity = MedicineBean.class, optional = false)
	private Medicine medicine;

	@ManyToOne(targetEntity = OrderBean.class, optional = true)
	@JoinColumn(name = "ORDER_ID", updatable = false)
	private Order order;

	@ManyToOne(targetEntity = NotificationBean.class, optional = true)
	@JoinColumn(name = "NOTIFICATION_ID", updatable = false)
	private Notification notification;
	
	private boolean isAccepted;

	public MedicineOrderBean() {
		medicine = new MedicineBean();
		order = new OrderBean();
		orderNumber = new Random().nextLong();
	}

	public void updatePrice() {
		this.price = qty * medicine.getPrice();
	}

	public long getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(long orderNumber) {
		this.orderNumber = orderNumber;
	}

	public int getId() {
		return id;
	}

	public int getQty() {
		return qty;
	}

	public void setQty(int qty) {
		this.qty = qty;
	}

	public Medicine getMedicine() {
		return medicine;
	}

	public void setMedicine(Medicine medicine) {
		this.medicine = medicine;
	}

	public double getPrice() {
		updatePrice();
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public Notification getNotification() {
		return notification;
	}

	public void setNotification(Notification notification) {
		this.notification = notification;
	}

	public boolean isAccepted() {
		return isAccepted;
	}

	public void setAccepted(boolean isAccepted) {
		this.isAccepted = isAccepted;
	}
}
